/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.actions.departamentos;

import com.mapping.Departamento;
import com.opensymphony.xwork2.ActionSupport;
import static com.opensymphony.xwork2.Action.SUCCESS;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Andres
 */
@Namespace(value="/")
@Action(value="verDepartamento", results={@Result(name="success",location="/GestionDepartamentos/verDepartamento.jsp")})
public class VerDepartamentoAction extends ActionSupport{
     private Departamento depa;
     private String id;
    
     @Override
    public String execute(){
         
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("inventarios");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();
        depa = (Departamento) em.createNamedQuery("Departamento.findByIdDepartamento").setParameter("idDepartamento", id).getSingleResult();
        tx.commit();
        em.close();
         
         return SUCCESS;
    }

    public Departamento getDepa() {
        return depa;
    }

    public void setId(String id) {
        this.id = id;
    }
     
}
